package com.dooioo.fangyou.common.page;

import java.util.List;
import org.apache.commons.lang3.StringUtils;

public class PageListImpl implements PageList {

	private static final long serialVersionUID = 1L;
	public final static int PAGE_NUMBER = 25;
	private int currentPage = 1; 
	private int totalNum; 
	private int pageNum = PAGE_NUMBER; 
	private int totalPage; 

	private boolean isNew = true; 
	private boolean isUp = false; 
	private boolean isDown = false; 

	private List list = null;
	
	private String query=null;
	
	public PageListImpl() {
	}
	
	public PageListImpl(int intPageNum) {
		   this.pageNum = intPageNum;
	}
	

	public int getBeginNum() {
		return (currentPage - 1) * pageNum + 1;
	}

	public int getEndNum() {
		return currentPage * pageNum+1;
	}

	/**
	 * @return
	 */
	public int getCurrentPage() {
		return currentPage;
	}

	/**
	 * @return
	 */
	public boolean isDown() {
		return isDown;
	}

	/**
	 * @return
	 */
	public boolean isNew() {
		return isNew;
	}

	/**
	 * @return
	 */
	public boolean isUp() {
		return isUp;
	}

	/**
	 * @return
	 */
	public int getPageNum() {
		return pageNum;
	}

	/**
	 * @return
	 */
	public int getTotalNum() {
		return totalNum;
	}

	/**
	 * @return
	 */
	public int getTotalPage() {
		if(totalPage>10000)
			return 10000;
		else 
			return totalPage;
		
	}

	/**
	 * @param i
	 */
	public void setCurrentPage(int i) {
		currentPage = i;
		isUp = currentPage > 1;
		isDown = (currentPage < (this.getTotalNum() / this.getPageNum() + 1));
	}

	/**
	 * @param b
	 */
	public void setNew(boolean b) {
		isNew = b;
	}

	/**
	 * @param i
	 */
	public void setPageNum(int i) {
		pageNum = i;
	}

	/**
	 * @param i
	 */
	public void setTotalNum(int i) {

		totalNum = i;
		if (totalNum % pageNum == 0) {
			totalPage = totalNum / pageNum;
		} else {
			totalPage = totalNum / pageNum + 1;
		}
		if (currentPage < totalPage) {
			isDown = true;
		}
		if (currentPage > 1) {
			isUp = true;
		}
	}

	/**
	 * @return
	 */
	public List getList() {
		return list;
	}

	/**
	 * @param list
	 */
	public void setList(List list) {
		this.list = list;
	}

	public String toString() {
		StringBuffer bf = new StringBuffer("current Page=");
		bf.append(currentPage);
		bf.append(" ,total Num=");
		bf.append(totalNum);
		bf.append(" ,page Num=");
		bf.append(pageNum);
		bf.append(" ,total Page=");
		bf.append(totalPage);
		bf.append(" ,is New=");
		bf.append(isNew);
		bf.append(" ,is Up=");
		bf.append(isUp);
		bf.append(" ,is Down=");
		bf.append(isDown);
		return bf.toString();
	}
	
	public boolean isNew(String page){
	   return StringUtils.isEmpty(page);
	}

}
